package com.eqdd.yiqidian.ui.yiqiyue.fragment;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewFragmentCustom;
import com.eqdd.yiqidian.bean.rebuild.TipBean;
import com.eqdd.yiqidian.box.ItemDecoration.SectionDividerItemDecoration;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseFragment;
import com.eqdd.yiqidian.ui.mine.setting.FeedbackActivity;
import com.eqdd.yiqidian.ui.yiqiyue.YueAttentionListActivity;
import com.eqdd.yiqidian.ui.yiqiyue.YueCollectionActivity;
import com.eqdd.yiqidian.ui.yiqiyue.YueFansListActivity;
import com.eqdd.yiqidian.ui.yiqiyue.YueMenuListActivity;
import com.eqdd.yiqidian.ui.yiqiyue.YueMyArticleListActivity;
import com.eqdd.yiqidian.ui.yiqiyue.YueZanListActivity;

import java.util.ArrayList;

/**
 * @author吕志豪 .
 * @date 17-12-9  下午1:40.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class YueMineFragment extends BaseFragment {
    RecyclerViewFragmentCustom dataBinding;
    private SlimAdapterEx slimAdapterEx;

    private Class[] classes = new Class[]{
            YueMenuListActivity.class,
            YueMyArticleListActivity.class,
            YueAttentionListActivity.class,
            YueFansListActivity.class,
            YueCollectionActivity.class,
            YueZanListActivity.class,
            FeedbackActivity.class,
    };

    @Override
    protected void setView() {


    }

    @Override
    protected void initData() {
        if (slimAdapterEx == null) {
            dataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
            slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_15, new SlimInjector<TipBean>() {
                @Override
                public void onInject(TipBean data, IViewInjector injector) {
                    injector.text(R.id.tv_title, data.getTitle())
                            .image(R.id.iv_head, data.getResId());
                    if (data.getNum() > 0) {
                        injector.gone(R.id.drag_point_view);
                        injector.visible(R.id.red_dot);
                        injector.text(R.id.drag_point_view, data.getNum() + "");
                    } else {
                        injector.gone(R.id.drag_point_view);
                        injector.gone(R.id.red_dot);
                    }
                }
            }).attachTo(dataBinding.recyclerView);
            ArrayList<TipBean> data = new ArrayList<>();
            data.add(new TipBean(R.mipmap.eqdr_wenjianjia, "我的文集"));
            data.add(new TipBean(R.mipmap.eqdr_wenzhang, "我的文章（公开，私有）"));
            data.add(new TipBean(R.mipmap.eqdr_guanzhu, "我的关注"));
            data.add(new TipBean(R.mipmap.eqdr_fensi, "我的粉丝"));
            data.add(new TipBean(R.mipmap.eqdr_shoucang, "收藏的文章"));
            data.add(new TipBean(R.mipmap.eqdr_zan, "喜欢的文章"));
            data.add(new TipBean(R.mipmap.eqdr_fankui, "帮助与反馈"));
            dataBinding.recyclerView.addItemDecoration(new SectionDividerItemDecoration(getActivity(), 4, 2, 1));
            slimAdapterEx.updateData(data);
            ItemClickSupport.addTo(dataBinding.recyclerView)
                    .setOnItemClickListener((recyclerView, position, v) -> {
                        if (classes[position] != null) {
                            startActivity(classes[position]);
                        }
                    });
        }

    }


    @Override
    public ViewDataBinding initBinding(LayoutInflater inflater) {
        return dataBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_recycler_view, null, false);

    }

    @Override
    public void onClick(View v) {

    }
}
